package org.yang.faq.service.impl;

import org.yang.faq.dao.CommentMapper;
import org.yang.faq.model.Comment;
import org.yang.faq.model.Program;
import org.yang.faq.service.CommentService;
import org.yang.faq.service.ProgramService;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author Yang
 * @since 2017-12-12
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {
	
	@Autowired
	private ProgramService programService; 
	
	@Override
	public String doComment(Comment comment) {
		//添加评论
		Boolean result = this.insert(comment);
		//更新节目单评论数
		
		EntityWrapper wrapper = new EntityWrapper<Program>();
		wrapper.eq("id", comment.getpId());
		Program program = programService.selectOne(wrapper);
		
		program.setCommentCount(program.getCommentCount()+1);
		programService.insertOrUpdate(program);

		if (result) {
			return "评论成功";
		} else {
			return "评论失败";
		}
	}

}
